From: Etienne Champetier Date: Wed, 3 Sep 2025 18:12:27 +0000 (-0400) Subject: ostree-soft-reboot: fix sysroot.mount umount X-Git-Tag: archive/raspbian/2025.7-2+rpi1^2^2~6^2~1^2~1^2~1 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=ded8a3dc69617ac9068a0e29c0b3bbe44802c0c2;p=ostree.git ostree-soft-reboot: fix sysroot.mount umount The composefs at /run/nextboot uses /sysroot, so systemd fails to umount sysroot.mount during soft-reboot. Create a temporary bind-mount, use it to prepare /run/nextboot and MNT_DETACH it when we are done. --- diff --git a/src/libostree/ostree-soft-reboot.c b/src/libostree/ostree-soft-reboot.c index 809b7991..a015cb4d 100644 --- a/src/libostree/ostree-soft-reboot.c +++ b/src/libostree/ostree-soft-reboot.c @@ -63,6 +63,22 @@ _ostree_prepare_soft_reboot (GError **error) if (!glnx_shutil_mkdir_p_at (AT_FDCWD, OTCORE_RUN_NEXTROOT, 0755, NULL, error)) return FALSE; + /* Bind-mount /sysroot on itself. + * The composefs mount at /run/nextboot is going to use /sysroot, + * causing systemd to fail to umount sysroot.mount during soft-reboot. + * Create a temporary bind-mount, and MNT_DETACH it when we are done + */ + if (mount (sysroot_path, sysroot_path, NULL, MS_BIND | MS_SILENT, NULL) < 0) + err (EXIT_FAILURE, "failed to MS_BIND '%s'", sysroot_path); + + /* Our curent working directory is in the old /sysroot, + * ie we are under the bind mount, so run 'cd $PWD' + * to move to the new /sysroot + */ + g_autofree char *cwd = g_get_current_dir (); + if (chdir (cwd) < 0) + err (EXIT_FAILURE, "failed to chdir to '%s'", cwd); + // Tracks if we did successfully enable it at runtime bool using_composefs = false; if (!otcore_mount_rootfs (rootfs_config, &metadata_builder, sysroot_path, target_deployment, @@ -78,6 +94,14 @@ _ostree_prepare_soft_reboot (GError **error) if (!otcore_mount_etc (config, &metadata_builder, OTCORE_RUN_NEXTROOT, error)) return FALSE; + // detach the temporary /sysroot bind-mount + if (umount2 (sysroot_path, MNT_DETACH) < 0) + err (EXIT_FAILURE, "failed to MS_DETACH '%s'", sysroot_path); + + // run 'cd $PWD' again to go back to the old /sysroot + if (chdir (cwd) < 0) + err (EXIT_FAILURE, "failed to chdir to '%s'", cwd); + // And set up /sysroot. Here since we hardcode composefs, we also hardcode // having a read-only /sysroot. g_variant_builder_add (&metadata_builder, "{sv}", OTCORE_RUN_BOOTED_KEY_SYSROOT_RO,